package com.haisen.controller;


import com.haisen.core.utils.PageResultSet;
import com.haisen.core.utils.Result;
import com.haisen.dataobject.entity.JobNo;
import com.haisen.dataobject.query.JobNoQuery;
import com.haisen.service.JobNoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/jobno")
@Slf4j
public class JobNoServcieController {

    @Autowired
    private JobNoService jobNoService;

    @GetMapping
   // @RequiresPermissions("jobno:view")
    private String page(Model model) {
        setCommonDate(model);
        return "jobno/jobno";
    }

    @ResponseBody
   // @RequiresPermissions("jobno:view")
    @GetMapping("/list")
    public PageResultSet<JobNo> list(JobNoQuery jobNoQuery) {
        return jobNoService.findByPager(jobNoQuery);
    }

    @ResponseBody
   // @RequiresPermissions("jobno:create")
    @PostMapping("/create")
    public Result create(@Validated JobNo jobNo) {
        jobNoService.create(jobNo);
        return Result.success();
    }

    @ResponseBody
   // @RequiresPermissions("jobno:update")
    @PostMapping("/update")
    public Result update(@Validated JobNo jobNo) {
        jobNoService.update(jobNo);
        return Result.success();
    }

    @ResponseBody
    @RequiresPermissions("jobno:delete")
    @PostMapping("/delete")
    public Result delete(@RequestParam("id") Long[] ids) {
        jobNoService.delete(ids);
        return Result.success();
    }

    @ResponseBody
    @GetMapping("/autocomplete")
    public Result autoComplete(@RequestParam("name") String name) {
        List<String> retList = jobNoService.autoComplete(name);
        return Result.success(retList);
    }


    private void setCommonDate(Model model) {

    }


}
